# @Time: 2020/10/11 13:33
# @Author: may
# @Desc:
import datetime
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from config import get_cfg

parameter = {'driver': ''}


def get_date(option):
    """获取日期"""

    # 今天
    today = datetime.datetime.now()
    # 明天
    tomorrow = (today + datetime.timedelta(days=+1)).strftime("%Y-%m-%d")
    # 后天
    the_day_after_tomorrow = (today + datetime.timedelta(days=+2)).strftime("%Y-%m-%d")
    # 昨天
    yesterday = (today + datetime.timedelta(days=-1)).strftime("%Y-%m-%d")
    date = {0: yesterday, 1: today.strftime("%Y-%m-%d"), 2: tomorrow, 3: the_day_after_tomorrow}
    return date[option]


def get_driver():
    """获取谷歌driver"""
    # token = get_cfg('url', 'token')
    # user_info = '{"auto":"1         ","flag":"1","flag1":"1","readlog":"yidu","Rid1":0,' \
    #             '"UserName":"91131102588192882J","Zsxm":"","Rdes":"本单位的系统管理员","Nsrsbh":"91131102588192882J",' \
    #             '"Rname":"系统管理员","isHx":"0","Rid":90000092,"PassWord":"","Lsswjg":"1311027634",' \
    #             '"Version":"1.2.39","isSale":"-1","Nsrsbh1":"91131102588192882J","Ocode":"91131102588192882J",' \
    #             '"IDUser":"90000093",' \
    #             '"token":"%s"}' % token
    header = get_cfg('header', 'headless')
    # js = 'window.localStorage.setItem("userInfo", \'{}\')'.format(user_info)
    if header == '1':
        # 启动谷歌无界面浏览器
        options = Options()
        options.add_argument('--headless')
        options.add_argument('--disable-gpu')
        driver = webdriver.Chrome(options=options)
    else:
        driver = webdriver.Chrome()
    return driver
